local png = require "png"
local lv = require "lv_img"
--lvgl中代表16位色
local color = 16
--lvgl的宏:LV_IMG_CF_TRUE_COLOR  =4,根据实际去修改
--lvgl的宏:LV_IMG_CF_TRUE_COLOR  =5,根据实际去修改

--[[
    path_t:文件列表
    save_path:保存文件的地址
--]]
function png_saveLv(path_t,save_path,tranColor,replaceColor)
	local cf = 4
    local rgb_buf,w,h,fp,read_buf
    local filename
    replaceColor = tonumber(replaceColor) or 0
    tranColor    = tonumber(tranColor) or 0
    --轮询rgb图片的地址,并且转换成lvImg的数据格式
    for k,v in ipairs(path_t) do
        fp = io.open(v.path,"rb")
        read_buf = fp:read("*a")
        fp:close()

        w,h,rgb_buf = png.png_to_rgb(read_buf,tranColor,replaceColor)
        filename = string.format("%s%s.lv",save_path,v.filename)
        fp = io.open(filename,"wb")
        --写入数据头
        fp:write(lv.getlvImg(color,cf,w,h))
        --保存rgb数据
        fp:write(rgb_buf)
        fp:close()
        
    end
end


function png_saveLvA(path_t,save_path,tranColor,replaceColor)
	local cf = 5
    local rgb_buf,w,h,fp,read_buf
    local filename
    replaceColor = tonumber(replaceColor) or 0
    tranColor    = tonumber(tranColor) or 0
    --轮询rgb图片的地址,并且转换成lvImg的数据格式
    for k,v in ipairs(path_t) do
        fp = io.open(v.path,"rb")
        read_buf = fp:read("*a")
        fp:close()

        w,h,rgb_buf = png.png_to_argb(read_buf,tranColor,replaceColor)
        filename = string.format("%s%s.lv",save_path,v.filename)
        fp = io.open(filename,"wb")
        --写入数据头
        fp:write(lv.getlvImg(color,cf,w,h))
        --保存rgb数据
        fp:write(rgb_buf)
        fp:close()
        
    end
end